package com.junzhiit.nengji.shop.web.util;

import java.text.DecimalFormat;
import java.util.Date;
import java.util.Random;

import org.apache.commons.lang3.RandomUtils;

public class OrderNumberUtils {
	
	public static final String BRAND_NUMBER_PREFIX = "B";
	
	public static final String ROLE_NUMBER_PREFIX = "R";
	
	public static final String FUNCTION_NUMBER_PREFIX = "F";
	
	public static final String TYPE_NUMBER_PREFIX = "T";
	
	private static final String ORDER_NUMBER_PREFIX = "CK";
	
	public static final String ADVERTISE_TYPE_NUMBER_PREFIX = "T";
	
	public static final String SHOP_NUMBER_PREFIX = "S";
	
	public static final int SHOP_CLIENT_DIGIT = 6;
	
	public static String getNumber(String storeCode){
		String timestamp = Long.toString(new Date().getTime());
		return new StringBuilder(timestamp.substring(0, 4))
				.append(timestamp.substring(4, timestamp.length())).toString();
	}
	
	public static String getSystemCode(String prefix,int value){
		DecimalFormat df =  new DecimalFormat("000");
		return prefix + df.format(value);
	}
	
	public static String getUserCode (int value){
		DecimalFormat df =  new DecimalFormat("000");
		return df.format(value);
	}
	
	/*public static String getOrderlNumber(){
		return ORDER_NUMBER_PREFIX + DateUtil.parseDateToString(new Date(), DateUtil.DATETIME_PATTERN_SECOND_SHORT);
	}
	*/
	public static String getRandomNumber(){
		String timestamp = Long.toString(new Date().getTime());
		int value = RandomUtils.nextInt(1, 9999);
		return timestamp.substring(4,8) + value;
	}
	
	public static String getOrderlNumber(){
		int max = 99999;
        int min = 10000;
        Random random = new Random();
        int num = random.nextInt(99999)%(max-min+1) + min;
        String number = String.valueOf(num) + String.valueOf(new Date().getTime()).substring(2, 13);
		return number;
	}
	
	public static String getOrderQrCodeNumber(){
		int max = 9999;
        int min = 1000;
        Random random = new Random();
        int num = random.nextInt(9999)%(max-min+1) + min;
        String number = String.valueOf(num) + String.valueOf(new Date().getTime()).substring(7, 13);
		return number;
	}
	
	public static String cardNumber(String maxNumber,int digit){
		StringBuffer newNumber = new StringBuffer("");
		if(maxNumber == null || "".equals(maxNumber)){
			for(int i = 0;i<digit-1;i++){
				newNumber.append("0");
			}
			newNumber.append("1");
		}else{
			Integer max = Integer.parseInt(maxNumber)+1;
			String critical = max.toString();
			for(int i =0,t=digit-critical.length();i<t;i++){
				newNumber.append("0");
			}
			newNumber.append(max);
		}
		return newNumber.toString();
	}
	
	public static void main(String[] args) {
		getRandomNumber();
		System.out.println(getSystemCode("B",1));
		String maxCode = "B001";
		System.out.println(Integer.valueOf(maxCode.substring(1, maxCode.length())));
	}
}
